package com.cola.springmvc.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Grup:com.cola.springmvc.exception
 * @Auther:cola
 * @Data:2021/5/9-2021-05-1:09
 * @version:1.0
 */
@ControllerAdvice
public class MyExceptionHandler {
    @ExceptionHandler(Exception.class)//class类型处理特定类型的异常

    public ModelAndView handleException(Exception e){
        System.out.println("出现全局异常"+e);
        ModelAndView mv=new ModelAndView();
        mv.setViewName("error");
        mv.addObject("exception",e);
        return mv;
    }
}
